package Productor_customer;

import java.util.Arrays;

public class ZhengTi<T> {
    private T[] zt;
    private int index;

    public ZhengTi(int size) {
        zt=(T[])new Object[size];
    }
    public synchronized void add(T t){
        while (index>=zt.length){
            try {
                wait();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        zt[index]=t;
        index++;
        notifyAll();
    }
    public synchronized T take(){
        while (index==0){
            try {
                wait();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        index--;
        T t=zt[index];
        notifyAll();
        return t;
    }

}
